//
//  GRFMFileTool.m
//  GRFMDownloader_Example
//
//  Created by Guo Rui on 2018/1/11.
//  Copyright © 2018年 GR. All rights reserved.
//

#import "GRFMFileTool.h"

@implementation GRFMFileTool

+ (BOOL)fileExists:(NSString *)path
{
    if (path == nil || path.length == 0) {
        return NO;
    }
    
    return [[NSFileManager defaultManager] fileExistsAtPath:path];
}

+ (long long)fileSize:(NSString *)path
{
    if (![self fileExists:path]) {
        return 0;
    }
    
    NSDictionary *fileInfo = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
    return [[fileInfo objectForKey:NSFileSize] longLongValue];
}

+ (BOOL)removeFile:(NSString *)path
{
    return [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}

+ (void)moveFile:(NSString *)frompath toPath:(NSString *)topath
{
    if (![self fileExists:frompath]) {
        return;
    }
    [[NSFileManager defaultManager] moveItemAtPath:frompath toPath:topath error:nil];
}

+ (void)createDirectory:(NSString *)path
{
    [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
}

@end
